//
//  ZZCComposeButton.swift
//  weibo
//
//  Created by zhangzuchao on 2017/4/2.
//  Copyright © 2017年 zhangZuChao. All rights reserved.
//

import UIKit


//  "撰写"菜单按钮
class ZZCComposeButton: UIButton {

    override init(frame: CGRect) {
        super.init(frame: frame)
        //  使用原始图片居中显示
        imageView?.contentMode = .center
        //  文字居中
        titleLabel?.textAlignment = .center
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //  调整子控件的布局
    override func layoutSubviews() {
        super.layoutSubviews()
        //  设置图片的y轴
        imageView?.frame.origin.y = 0
        imageView?.frame.origin.x = 0
        //  设置图片的大小
        imageView?.frame.size.width = bounds.size.width
        imageView?.frame.size.height = bounds.size.width
        
        //  设置titlelabe的y轴, 当前按钮的高度减去按钮的高度表示titleLabel的y轴
        titleLabel?.frame.origin.y = bounds.size.width
        titleLabel?.frame.origin.x = 0
        
        //  设置文字的大小
        titleLabel?.frame.size.width = bounds.size.width
        titleLabel?.frame.size.height = bounds.size.height - bounds.size.width
        
    }


}
